<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 14/01/2019
 * Time: 17:46
 */

namespace App\Models\Cargo;


use App\Models\BaseModel;
use Carbon\Carbon;

class Cargo extends BaseModel
{
    protected $table = 'cargos';

    public $dateFormat = 'Y-m-d H:i:s';

    public function user()
    {
        return $this->belongsTo('App\Models\User\User', 'user_id', 'id')->select('id', 'name', 'public_phone', 'head_portrait');
    }

    protected $status_text     = [0 => '已关闭', 1 => '发布中', 2 => '已接单'];
    protected $is_auto_text    = [0 => '不选择', 1 => '智能发货'];
    protected $is_discuss_text = [0 => '不协商', 1 => '协商'];
    protected $is_common_text  = [0 => '否', 1 => '是'];
    protected $is_visible_text = [0 => '不可见', 1 => '可见'];

    public function getStatusAttribute($key)
    {
        return $this->status_text[$key];
    }

    public function getIsAutoAttribute($key)
    {
        return $this->is_auto_text[$key];
    }

    public function getIsDiscussAttribute($key)
    {
        return $this->is_discuss_text[$key];
    }

    public function getIsCommonAttribute($key)
    {
        return $this->is_common_text[$key];
    }

    public function getIsVisibleAttribute($key)
    {
        return $this->is_visible_text[$key];
    }

    public function getCreatedAtAttribute($date)
    {
        return Carbon::createFromTimestamp(strtotime($date))->diffForHumans();
    }

    public function getUpdatedAtAttribute($date)
    {
        return Carbon::createFromTimestamp(strtotime($date))->diffForHumans();
    }

}
